﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    layui.use(['jquery', 'form', 'table', 'common', 'optimizeSelectOption'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            common = layui.common;
        //加载数据
        wcLoading.close();
        //权限控制(js是值传递)
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
       common.rendertable({
           elem: '#currentTableId',
           id: 'currentTableId',
            url: '/SystemSecurity/FilterIP/GetGridJson',
           page: false,
            cols: [[                
                {
                    field: 'F_Type', title: '策略类型', width: 120, sort: true,
                    templet: function (d) {
                        if (d.F_Type == true) {
                            return "<span class=\"layui-bg-green\">允许访问</span>";
                        } else {
                            return "<span class=\"layui-bg-red\">禁止访问</span>";
                        }
                    }
                },
                { field: 'F_StartIP', title: '起始IP', width: 150, sort: true },
                { field: 'F_EndIP', title: '结束IP', width: 150, sort: true },
                {
                    field: 'F_CreatorTime', title: '创建时间', width: 120, sort: true,
                    templet: function (d) {
                        if (d.F_CreatorTime) {
                            var time = new Date(d.F_CreatorTime);
                            return time.Format("yyyy-MM-dd");
                        }
                    }
                },
                {
                    field: 'F_EnabledMark', title: '有效', Width: 80, sort: true,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<input type='checkbox' checked='' lay-skin='primary' name='true' valuer='true'>";
                        } else {
                            return "<input type='checkbox' name='false'  lay-skin='primary' valuer='false'>";
                        }
                    }
                },
                { field: 'F_Description', title: '备注', minWidth: 150},
           ]]
       });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            common.reloadtable({
                elem: 'currentTableId',
                page:false,
                curr: 1,
                where: { keyword: data.field.txt_keyword }
            });
            fitlerIP = null;
            return false;
        });
        var fitlerIP;
        table.on('row(currentTableFilter)', function (obj) {
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            fitlerIP = obj;
        })
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听删除操作
                common.modalOpen({
                    title: "添加策略",
                    url: "/SystemSecurity/FilterIP/Form",
                    width: "450px",
                    height: "480px",
                });
            }
            else if (obj.event === 'delete') {
                if (fitlerIP==null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/SystemSecurity/FilterIP/DeleteForm",
                    param: { keyValue: fitlerIP.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (fitlerIP == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "添加策略",
                    url: "/SystemSecurity/FilterIP/Form?keyValue=" + fitlerIP.data.F_Id,
                    width: "450px",
                    height: "480px",
                });
            }
            else if (obj.event === 'details'){
                if (fitlerIP == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "查看策略",
                    url: "/SystemSecurity/FilterIP/Details?keyValue=" + fitlerIP.data.F_Id,
                    width: "450px",
                    height: "450px",
                    btn:[]
                    //callBack: function (index) {
                    //    var iframe = "layui-layer-iframe" + index;
                    //    window.frames[iframe].submitForm();
                    //}
                });
            }
            return false;
        });
    });
</script>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            @*<legend>搜索信息</legend>*@
            <div>
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                <button id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>